package com.lemniscate.audio_and_video_demo.activity;

import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.lemniscate.audio_and_video_demo.R;
import com.lemniscate.audio_and_video_demo.utils.AudioRecordUtils;
import com.lemniscate.audio_and_video_demo.utils.AudioTrackUtils;

import java.io.File;

/**
 * Created by l on 2018/2/28.
 */

public class AudioRecordActivity2 extends AppCompatActivity {

    String filePath = "";
    String wavFilePath = "";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_audiorecordactivity2);
        initSavePath();
    }

    private void initSavePath() {
        File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/test");
        file.mkdirs();

        filePath = file.getAbsolutePath() + "/recordtest.pcm";
        wavFilePath = file.getAbsolutePath() + "/recordtest.wav";
    }


    public void record(View view) {
        AudioRecordUtils.getInstance().startRecord(filePath, wavFilePath);
    }

    public void stoprecord(View view) {
        AudioRecordUtils.getInstance().stopRecord();
    }


    public void play(View view) {
        AudioTrackUtils.getInstance().play(filePath);
    }


    public void stopplay(View view) {
        AudioTrackUtils.getInstance().stop();
    }
}
